<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Denzel - 几个有用的Web API——全屏模式</title>
    <meta name="description" content="前端笔记">
    <meta name="keywords" content="web前端,HTML5,CSS3,Javascript,SVG,canvas">
  <meta name="anthor" content="Denzel">
  <meta name="theme-color" content="#3eaf7c">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="msapplication-TileImage" content="/icons/msapplication-icon-144x144.png">
  <meta name="msapplication-TileColor" content="#000000">
  <link rel="icon" href="/blog/vuepress/logo.png">
  <link rel="manifest" href="/blog/vuepress/manifest.json">
  <link rel="apple-touch-icon" href="/blog/vuepress/icons/apple-touch-icon-152x152.png">
  <link rel="mask-icon" href="/blog/vuepress/icons/safari-pinned-tab.svg" color="#3eaf7c">
    
    <link rel="preload" href="/blog/vuepress/assets/css/0.styles.d4f29607.css" as="style"><link rel="preload" href="/blog/vuepress/assets/js/app.15770e34.js" as="script"><link rel="preload" href="/blog/vuepress/assets/js/26.83a2ddc3.js" as="script"><link rel="preload" href="/blog/vuepress/assets/js/59.5d1d0ce6.js" as="script"><link rel="preload" href="/blog/vuepress/assets/js/58.636557fa.js" as="script"><link rel="preload" href="/blog/vuepress/assets/js/57.bd168a1e.js" as="script"><link rel="prefetch" href="/blog/vuepress/assets/js/46.59c0ece7.js"><link rel="prefetch" href="/blog/vuepress/assets/js/1.05e4270f.js"><link rel="prefetch" href="/blog/vuepress/assets/js/2.ace739f7.js"><link rel="prefetch" href="/blog/vuepress/assets/js/3.636e5a79.js"><link rel="prefetch" href="/blog/vuepress/assets/js/4.7a55aa4b.js"><link rel="prefetch" href="/blog/vuepress/assets/js/5.b56b0573.js"><link rel="prefetch" href="/blog/vuepress/assets/js/6.e9a3fbc8.js"><link rel="prefetch" href="/blog/vuepress/assets/js/7.aa46c47d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/8.a9288ac6.js"><link rel="prefetch" href="/blog/vuepress/assets/js/9.b9f8dec6.js"><link rel="prefetch" href="/blog/vuepress/assets/js/10.3e2ea470.js"><link rel="prefetch" href="/blog/vuepress/assets/js/11.4d115f98.js"><link rel="prefetch" href="/blog/vuepress/assets/js/12.c97cf4d0.js"><link rel="prefetch" href="/blog/vuepress/assets/js/13.1e0cf594.js"><link rel="prefetch" href="/blog/vuepress/assets/js/14.bab9026a.js"><link rel="prefetch" href="/blog/vuepress/assets/js/15.1a24cffe.js"><link rel="prefetch" href="/blog/vuepress/assets/js/16.e9995850.js"><link rel="prefetch" href="/blog/vuepress/assets/js/17.86a1f7d2.js"><link rel="prefetch" href="/blog/vuepress/assets/js/18.c32400c4.js"><link rel="prefetch" href="/blog/vuepress/assets/js/19.9f99887c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/20.82f0c2f9.js"><link rel="prefetch" href="/blog/vuepress/assets/js/21.7f5c223d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/22.acf9934c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/23.20d8e817.js"><link rel="prefetch" href="/blog/vuepress/assets/js/24.acf27379.js"><link rel="prefetch" href="/blog/vuepress/assets/js/25.20165510.js"><link rel="prefetch" href="/blog/vuepress/assets/js/27.33276a04.js"><link rel="prefetch" href="/blog/vuepress/assets/js/28.e320efab.js"><link rel="prefetch" href="/blog/vuepress/assets/js/29.3fd92c30.js"><link rel="prefetch" href="/blog/vuepress/assets/js/30.2bc84d43.js"><link rel="prefetch" href="/blog/vuepress/assets/js/31.d70ed500.js"><link rel="prefetch" href="/blog/vuepress/assets/js/32.e7a0f8e1.js"><link rel="prefetch" href="/blog/vuepress/assets/js/33.c48ee70b.js"><link rel="prefetch" href="/blog/vuepress/assets/js/34.8ad03d1b.js"><link rel="prefetch" href="/blog/vuepress/assets/js/35.5bdb3994.js"><link rel="prefetch" href="/blog/vuepress/assets/js/36.a25f926e.js"><link rel="prefetch" href="/blog/vuepress/assets/js/37.7515cfbb.js"><link rel="prefetch" href="/blog/vuepress/assets/js/38.99347371.js"><link rel="prefetch" href="/blog/vuepress/assets/js/39.3481fc62.js"><link rel="prefetch" href="/blog/vuepress/assets/js/40.bc709734.js"><link rel="prefetch" href="/blog/vuepress/assets/js/41.e1e0a3bf.js"><link rel="prefetch" href="/blog/vuepress/assets/js/42.762b61b0.js"><link rel="prefetch" href="/blog/vuepress/assets/js/43.8f0b2d6c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/44.2a0a4ee0.js"><link rel="prefetch" href="/blog/vuepress/assets/js/45.baf7ed60.js"><link rel="prefetch" href="/blog/vuepress/assets/js/47.11a8720a.js"><link rel="prefetch" href="/blog/vuepress/assets/js/48.e0bf8b54.js"><link rel="prefetch" href="/blog/vuepress/assets/js/49.c96c4011.js"><link rel="prefetch" href="/blog/vuepress/assets/js/50.31189263.js"><link rel="prefetch" href="/blog/vuepress/assets/js/51.766a8294.js"><link rel="prefetch" href="/blog/vuepress/assets/js/52.26b971fd.js"><link rel="prefetch" href="/blog/vuepress/assets/js/53.0cfbd708.js"><link rel="prefetch" href="/blog/vuepress/assets/js/54.bdc15c87.js"><link rel="prefetch" href="/blog/vuepress/assets/js/55.fea285a9.js"><link rel="prefetch" href="/blog/vuepress/assets/js/56.e030a6b2.js"><link rel="prefetch" href="/blog/vuepress/assets/js/60.0b779f92.js"><link rel="prefetch" href="/blog/vuepress/assets/js/61.4ec3f2eb.js"><link rel="prefetch" href="/blog/vuepress/assets/js/62.8f70f114.js"><link rel="prefetch" href="/blog/vuepress/assets/js/63.9ac2b61d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/64.c028fad5.js"><link rel="prefetch" href="/blog/vuepress/assets/js/65.923a8d15.js"><link rel="prefetch" href="/blog/vuepress/assets/js/66.73db652e.js"><link rel="prefetch" href="/blog/vuepress/assets/js/67.1a91446d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/68.e5a12a42.js"><link rel="prefetch" href="/blog/vuepress/assets/js/69.6ddcb882.js"><link rel="prefetch" href="/blog/vuepress/assets/js/70.ceb70d85.js"><link rel="prefetch" href="/blog/vuepress/assets/js/71.a804ef40.js"><link rel="prefetch" href="/blog/vuepress/assets/js/72.f1c4098c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/73.2f28b842.js"><link rel="prefetch" href="/blog/vuepress/assets/js/74.571c2ab1.js"><link rel="prefetch" href="/blog/vuepress/assets/js/75.f365c2a1.js"><link rel="prefetch" href="/blog/vuepress/assets/js/76.0916a3cd.js"><link rel="prefetch" href="/blog/vuepress/assets/js/77.469aed17.js"><link rel="prefetch" href="/blog/vuepress/assets/js/78.02cdd59d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/79.44d7f95c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/80.4ca072f1.js"><link rel="prefetch" href="/blog/vuepress/assets/js/81.d9239a49.js"><link rel="prefetch" href="/blog/vuepress/assets/js/82.b09096b2.js"><link rel="prefetch" href="/blog/vuepress/assets/js/83.f4bc8a9b.js"><link rel="prefetch" href="/blog/vuepress/assets/js/84.1ffe6969.js"><link rel="prefetch" href="/blog/vuepress/assets/js/85.44e980f9.js"><link rel="prefetch" href="/blog/vuepress/assets/js/86.c8579ac0.js"><link rel="prefetch" href="/blog/vuepress/assets/js/87.cd49f324.js"><link rel="prefetch" href="/blog/vuepress/assets/js/88.3851b6ff.js"><link rel="prefetch" href="/blog/vuepress/assets/js/89.b05297be.js"><link rel="prefetch" href="/blog/vuepress/assets/js/90.c1e3263e.js"><link rel="prefetch" href="/blog/vuepress/assets/js/91.b493a1bb.js"><link rel="prefetch" href="/blog/vuepress/assets/js/92.80ab06fd.js"><link rel="prefetch" href="/blog/vuepress/assets/js/93.c6ca00b3.js"><link rel="prefetch" href="/blog/vuepress/assets/js/94.e993d310.js"><link rel="prefetch" href="/blog/vuepress/assets/js/95.8e19a7ed.js">
    <link rel="stylesheet" href="/blog/vuepress/assets/css/0.styles.d4f29607.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div><a href="/blog/vuepress/" class="home-link router-link-active"><img src="/blog/vuepress/hero.png" class="logo"><span class="site-name can-hide">
      Denzel
    </span></a><div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""><!----></div><nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/vuepress/js/" class="nav-link router-link-active">JS</a></div><div class="nav-item"><a href="/blog/vuepress/css/" class="nav-link">CSS</a></div><div class="nav-item"><a href="/blog/vuepress/html/" class="nav-link">HTML</a></div><div class="nav-item"><a href="/blog/vuepress/else/" class="nav-link">其他</a></div><div class="nav-item"><a href="/blog/vuepress/study/" class="nav-link">study</a></div><a href="https://github.com/xiaotianxia" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header><div class="sidebar-mask"></div><div class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/blog/vuepress/js/" class="nav-link router-link-active">JS</a></div><div class="nav-item"><a href="/blog/vuepress/css/" class="nav-link">CSS</a></div><div class="nav-item"><a href="/blog/vuepress/html/" class="nav-link">HTML</a></div><div class="nav-item"><a href="/blog/vuepress/else/" class="nav-link">其他</a></div><div class="nav-item"><a href="/blog/vuepress/study/" class="nav-link">study</a></div><a href="https://github.com/xiaotianxia" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav><ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>JS</span><!----></p><ul class="sidebar-group-items"><li><a href="/blog/vuepress/js/" class="sidebar-link">目录</a></li><li><a href="/blog/vuepress/js/four_kinds_of_observers.html" class="sidebar-link">JS中的观察者们 —— 四种 Observers</a></li><li><a href="/blog/vuepress/js/editable_dom.html" class="sidebar-link">可编辑的页面——designMode、contenteditable和user-modify</a></li><li><a href="/blog/vuepress/js/useful_webapis_mediarecorder.html" class="sidebar-link">用浏览器轻松录制音频、视频—— MediaRecorder API</a></li><li><a href="/blog/vuepress/js/useful_webapis_audiocontext.html" class="sidebar-link">让你的网页开口说话 —— audioContext API</a></li><li><a href="/blog/vuepress/js/useful_webapis_fullscreen.html" class="active sidebar-link">几个有用的Web API——全屏模式</a></li><li><a href="/blog/vuepress/js/useful_webapis_notification.html" class="sidebar-link">几个有用的Web API——桌面通知API</a></li><li><a href="/blog/vuepress/js/useful_webapis_connection.html" class="sidebar-link">几个有用的Web API——网络状态API</a></li><li><a href="/blog/vuepress/js/useful_webapis_geolocation.html" class="sidebar-link">几个有用的Web API——地理位置API</a></li><li><a href="/blog/vuepress/js/speech_in_js_recognition.html" class="sidebar-link">JS中的语音识别——Speech Recognition API</a></li><li><a href="/blog/vuepress/js/speech_in_js_synthesis.html" class="sidebar-link">JS中的语音合成——Speech Synthesis API</a></li><li><a href="/blog/vuepress/js/camera_in_js_trial.html" class="sidebar-link">JS控制设备摄像头初探</a></li><li><a href="/blog/vuepress/js/shape_detection_api_trial.html" class="sidebar-link">浏览器的图像识别API初探</a></li><li><a href="/blog/vuepress/js/simple_chatroom_using_socketio.html" class="sidebar-link">socket.io实现简单群聊</a></li><li><a href="/blog/vuepress/js/communication_using_postmessage.html" class="sidebar-link">postMessage实现父子页面简单通信</a></li><li><a href="/blog/vuepress/js/upload_using_filereader_createobjecturl.html" class="sidebar-link">FileReader与URL.createObjectURL实现图片、视频上传预览</a></li><li><a href="/blog/vuepress/js/simple_code_preview.html" class="sidebar-link">前端几行代码简单实现w3school代码预览</a></li></ul></div></li></ul></div><div class="page"><div class="content"><h1 id="几个有用的web-api——全屏模式"><a href="#几个有用的web-api——全屏模式" aria-hidden="true" class="header-anchor">#</a> 几个有用的Web API——全屏模式</h1><p><a href="https://denzel.netlify.com/js/useful_webapis_fullscreen.html?_=0987654334523" target="_blank" rel="noopener noreferrer">原文链接</a></p><h2 id="前言"><a href="#前言" aria-hidden="true" class="header-anchor">#</a> 前言</h2><p>全屏下播放视频已经很常见了，像这样
<img src="http://pn4meizzc.bkt.clouddn.com/fullscreen.jpeg" alt>
而在web页面里，几乎所有元素都是可以全屏显示的。全屏模式下，一切“闲杂”元素退出，
舞台只为你而亮，请开始你的表演。
<img src="http://pn4meizzc.bkt.clouddn.com/blogtimg.jpeg" alt></p><p>今天跟大家一块学习HTML5的全屏模式——fullscreen API。</p><p>先看一个例子↓：
<div class="fullscreen-wrapper1" data-v-74a14034><div class="block div" data-v-74a14034>div</div><span class="block span" data-v-74a14034>span</span><p class="block p" data-v-74a14034>p</p><h1 class="block h1" data-v-74a14034>h1</h1><a class="block a" data-v-74a14034>a</a><i class="block i" data-v-74a14034>i</i></div></p><p>可以看到，以上元素都是支持全屏模式的，但在全屏下元素的原本样式也发生了改变，
Chrome和Safari下，貌似表现的与<strong>display:inline</strong>一样，虽然我设置的是<strong>display:block</strong>。
不妨在Firefox下试试：Firefox下，则整个元素都是全屏的。
如下图：</p><p>Chrome、Safari：
<img src="http://pn4meizzc.bkt.clouddn.com/fullscreen002.png" alt>
Firefox：
<img src="http://pn4meizzc.bkt.clouddn.com/fullscreen003.png" alt>
关于样式稍后再说，我们先从头开始看。</p><p>首先看下mdn的解释：</p><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>只有包含在顶层文档内部的标准HTML元素、svg元素和math元素，
以及拥有<strong>allowfullscreen</strong>属性的iframe的内部元素可以进入全屏模式。
这意味着在iframe内部的元素，以及object的内部元素不能进入全屏模式。</p></div><p>iframe可以全屏，但需要有属性allowfullscreen。</p><h2 id="两个方法"><a href="#两个方法" aria-hidden="true" class="header-anchor">#</a> 两个方法</h2><h3 id="requestfullscreen"><a href="#requestfullscreen" aria-hidden="true" class="header-anchor">#</a> requestFullscreen()</h3><p>触发元素的全屏模式：Element.requestFullscreen()</p><h3 id="exitfullscreen"><a href="#exitfullscreen" aria-hidden="true" class="header-anchor">#</a> exitFullscreen()</h3><p>退出全屏：document.exitFullscreen()</p><h2 id="两个事件"><a href="#两个事件" aria-hidden="true" class="header-anchor">#</a> 两个事件</h2><h3 id="fullscreenchange"><a href="#fullscreenchange" aria-hidden="true" class="header-anchor">#</a> fullscreenchange</h3><p>元素进入和退出全屏时都会触发</p><h3 id="fullscreenerror"><a href="#fullscreenerror" aria-hidden="true" class="header-anchor">#</a> fullscreenerror</h3><p>元素进入和退出全屏发生错误时触发</p><h2 id="两个属性"><a href="#两个属性" aria-hidden="true" class="header-anchor">#</a> 两个属性</h2><h3 id="fullscreenelement"><a href="#fullscreenelement" aria-hidden="true" class="header-anchor">#</a> fullscreenElement</h3><p>document.fullscreenElement 查看全屏的元素，没有则返回null</p><p>这个的支持度不高。</p><p>注：之前是document.fullscreen，返回true/false，已废弃。</p><h3 id="fullscreenenabled"><a href="#fullscreenenabled" aria-hidden="true" class="header-anchor">#</a> fullscreenEnabled</h3><p>document.fullscreenEnabled 当前是否支持进入全屏状态。</p><h2 id="样式"><a href="#样式" aria-hidden="true" class="header-anchor">#</a> 样式</h2><h3 id="fullscreen-伪类"><a href="#fullscreen-伪类" aria-hidden="true" class="header-anchor">#</a> :fullscreen 伪类</h3><p>要改变全屏下元素的样式，需要用到:fullscreen伪类。</p><pre class="language-css"><code><span class="token selector">div:-webkit-full-screen</span> <span class="token punctuation">{</span>
	<span class="token property">width</span><span class="token punctuation">:</span> 50%<span class="token punctuation">;</span>  <span class="token comment">/*Chrome下，width是相对于屏幕宽度的，而且元素自动居中对齐*/</span>
<span class="token punctuation">}</span>
</code></pre><p>全屏下Chrome会有默认加上白背景色和一个很大的z-index，这样婶的
<img src="http://pn4meizzc.bkt.clouddn.com/blogfullscreen001.png" alt>
所以手动改变全屏下的样式是有必要的。</p><p>而Firefox下，则看到了这样的代码，
<img src="http://pn4meizzc.bkt.clouddn.com/fullscreen004.png" alt>
而且试着改变这些样式貌似都不好使，求大神指点啊！！</p><pre class="language-css"><code><span class="token selector">div:-moz-full-screen</span> <span class="token punctuation">{</span>
	<span class="token property">width</span><span class="token punctuation">:</span> 50%<span class="token important">!important</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</code></pre><p>从这点上来看，自认为还是Chrome更合理一些呀。</p><h3 id="backdrop-伪元素"><a href="#backdrop-伪元素" aria-hidden="true" class="header-anchor">#</a> :backdrop 伪元素</h3><p>全屏模式的元素下的即刻渲染的盒子（并且在所有其他在堆中的层级更低的元素之上），可用来给下层文档设置样式或隐藏它。</p><pre class="language-css"><code><span class="token selector">.block::backdrop</span> <span class="token punctuation">{</span>
    <span class="token property">background</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>这个自测只有最新的Firefox支持。
如下图：
<img src="http://pn4meizzc.bkt.clouddn.com/blogfullscreen005.png" alt></p><blockquote><p>另：backdrop这个词还有两个地方用到：一个是<a href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/dialog" target="_blank" rel="noopener noreferrer">dialog</a>这个标签的伪元素，用来设置弹窗背景样式，这个浏览器的支持还是很好的。
还有一个是css滤镜<a href="https://developer.mozilla.org/zh-CN/docs/Web/CSS/backdrop-filter" target="_blank" rel="noopener noreferrer">backdrop-filter</a>，可自行查看。</p></blockquote><p>再来一个例子↓，里面用到了<a href="https://github.com/rafrex/fscreen" target="_blank" rel="noopener noreferrer">这个库</a>，它对各个方法和属性做了很好的兼容，在开发中可以作参考。
用法很简单，如</p><pre class="language-js"><code>fscreen<span class="token punctuation">.</span><span class="token function">requestFullscreen</span><span class="token punctuation">(</span>element<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//用来代替element.requestFullscreen()</span>
</code></pre><div class="fullscreen-wrapper2" data-v-14c41ff4><div class="fullscreen-content" data-v-14c41ff4><p data-v-14c41ff4>是否可全屏：<strong data-v-14c41ff4>false</strong></p><p data-v-14c41ff4>全屏模式：<strong data-v-14c41ff4>false</strong></p><p data-v-14c41ff4>fullscreenElement：<strong data-v-14c41ff4></strong></p><div class="block" data-v-14c41ff4></div></div></div><p>其中部分代码：</p><pre class="language-js"><code><span class="token keyword">import</span> fscreen <span class="token keyword">from</span> <span class="token string">'./fscreen.js'</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
	<span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">return</span> <span class="token punctuation">{</span>
			fullscreen<span class="token punctuation">:</span> <span class="token boolean">false</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>

	computed<span class="token punctuation">:</span> <span class="token punctuation">{</span>
		<span class="token function">fullscreenEnabled</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> fscreen<span class="token punctuation">.</span>fullscreenEnabled<span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">,</span>

		<span class="token function">fullscreenElement</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">return</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>fscreen<span class="token punctuation">.</span>fullscreenElement<span class="token punctuation">)</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>

	methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
		<span class="token function">onTriggerClick</span> <span class="token punctuation">(</span>e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>fullscreen<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">onExitFullsreen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">requestFullscreen</span><span class="token punctuation">(</span>document<span class="token punctuation">.</span><span class="token function">querySelector</span><span class="token punctuation">(</span><span class="token string">'.fullscreen-content'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>fullscreen <span class="token operator">=</span> <span class="token operator">!</span><span class="token keyword">this</span><span class="token punctuation">.</span>fullscreen<span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">,</span>

		<span class="token function">requestFullscreen</span> <span class="token punctuation">(</span>ele<span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span><span class="token punctuation">(</span>fscreen<span class="token punctuation">.</span>requestFullscreen<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">return</span> fscreen<span class="token punctuation">.</span><span class="token function">requestFullscreen</span><span class="token punctuation">(</span>ele<span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				<span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">'浏览器不支持全屏API'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">,</span>

		<span class="token function">onExitFullsreen</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span><span class="token punctuation">(</span>fscreen<span class="token punctuation">.</span>exitFullscreen<span class="token punctuation">)</span> <span class="token punctuation">{</span>
				<span class="token keyword">return</span> fscreen<span class="token punctuation">.</span><span class="token function">exitFullscreen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				<span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">'浏览器不支持全屏API'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">,</span>

	<span class="token function">mounted</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		fscreen<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'fullscreenchange'</span><span class="token punctuation">,</span> e <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>$message<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>fullscreen <span class="token operator">?</span> <span class="token string">'进入全屏'</span> <span class="token punctuation">:</span> <span class="token string">'退出全屏'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		fscreen<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'fullscreenerror'</span><span class="token punctuation">,</span> e <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
			<span class="token keyword">this</span><span class="token punctuation">.</span>$message<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">'全屏切换出错'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><pre class="language-css"><code><span class="token selector">.block</span> <span class="token punctuation">{</span>
	<span class="token property">display</span><span class="token punctuation">:</span> block<span class="token punctuation">;</span>
	<span class="token property">height</span><span class="token punctuation">:</span> 50px<span class="token punctuation">;</span>
	<span class="token property">width</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
	<span class="token property">margin</span><span class="token punctuation">:</span> 10px auto<span class="token punctuation">;</span>
	<span class="token property">cursor</span><span class="token punctuation">:</span> pointer<span class="token punctuation">;</span>
	<span class="token property">border-radius</span><span class="token punctuation">:</span> 5px<span class="token punctuation">;</span>
	<span class="token property">text-align</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
	<span class="token property">line-height</span><span class="token punctuation">:</span> 50px<span class="token punctuation">;</span>
	<span class="token property">font-size</span><span class="token punctuation">:</span> 18px<span class="token punctuation">;</span>
	<span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
	<span class="token property">background-color</span><span class="token punctuation">:</span> #2d3436<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">.block:before</span> <span class="token punctuation">{</span>
	<span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">'正常模式'</span><span class="token punctuation">;</span>
	<span class="token property">color</span><span class="token punctuation">:</span> #fff<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">.fullscreen-content</span> <span class="token punctuation">{</span>
	<span class="token property">width</span><span class="token punctuation">:</span> 400px<span class="token punctuation">;</span>
	<span class="token property">margin</span><span class="token punctuation">:</span> 10px auto<span class="token punctuation">;</span>
	<span class="token property">text-align</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">.fullscreen-content:fullscreen .block</span> <span class="token punctuation">{</span>
	<span class="token property">background-color</span><span class="token punctuation">:</span> #ff7675<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">.fullscreen-content:fullscreen .block:before</span> <span class="token punctuation">{</span>
	<span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">'全屏模式(点击退出)'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token selector">.fullscreen-content::backdrop</span> <span class="token punctuation">{</span>
	<span class="token property">position</span><span class="token punctuation">:</span> fixed<span class="token punctuation">;</span>
    <span class="token property">top</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
    <span class="token property">left</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
    <span class="token property">right</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
    <span class="token property">bottom</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
    <span class="token property">background</span><span class="token punctuation">:</span> green<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><h2 id="危险"><a href="#危险" aria-hidden="true" class="header-anchor">#</a> 危险</h2><p>有人提出这个API有个问题，那就是容易造成欺骗。在<a href="http://feross.org/html5-fullscreen-api-attack/" target="_blank" rel="noopener noreferrer">这里</a>有个demo，
比如某个链结写的是 http://www.×××.com ，大家以为是美国银行， 但是一点进去，因为使用了全屏幕API，就会欺骗到人，被成功钓鱼。
大概意思是这样婶的，看另一个例子↓：
<div class="fullscreen-wrapper3" data-v-6c247b19><a href="javascript:;" data-v-6c247b19>http://www.bank.com</a><div class="fullscreen-cheat" data-v-6c247b19>我是骗人的页面</div></div></p><h2 id="兼容性"><a href="#兼容性" aria-hidden="true" class="header-anchor">#</a> 兼容性</h2><p>手机端不出意料的全军覆没，pc端如下：</p><p>（各个浏览器还真是任性，各自的写法真实五花八门呐！来感受一下~）</p><table><thead><tr><th>标准</th><th>Blink (Chrome &amp; Opera)、Safari (WebKit)、Edge</th><th>Gecko (Firefox)</th><th>Internet Explorer 11</th></tr></thead><tbody><tr><td>document.fullscreenEnabled</td><td>webkitFullscreenEnabled</td><td>mozFullScreenEnabled</td><td>msFullscreenEnabled</td></tr><tr><td>document.fullscreenElement</td><td>webkitFullscreenElement</td><td>mozFullScreenElement</td><td>msFullscreenElement</td></tr><tr><td>document.onfullscreenchange</td><td>onwebkitfullscreenchange</td><td>onmozfullscreenchange</td><td>MSFullscreenChange</td></tr><tr><td>document.onfullscreenerror</td><td>onwebkitfullscreenerror</td><td>onmozfullscreenerror</td><td>MSFullscreenError</td></tr><tr><td>document.exitFullscreen()</td><td>webkitExitFullscreen()</td><td>mozCancelFullScreen()</td><td>msExitFullscreen()</td></tr><tr><td>element.requestFullscreen()</td><td>webkitRequestFullscreen()</td><td>mozRequestFullScreen()</td><td>msRequestFullscreen()</td></tr><tr><td>:fullscreen</td><td>:-webkit-full-screen</td><td>:-moz-full-screen</td><td>:-ms-fullscreen</td></tr></tbody></table><h2 id="总结"><a href="#总结" aria-hidden="true" class="header-anchor">#</a> 总结</h2><p>可以用来做啥呢？</p><ul><li>播放器全屏，司空见惯</li><li>页面小游戏全屏，如canvas游戏等</li><li>富文本编辑器全屏</li><li>还有啥呢...</li></ul><h2 id="参考资料"><a href="#参考资料" aria-hidden="true" class="header-anchor">#</a> 参考资料</h2><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API" target="_blank" rel="noopener noreferrer">Fullscreen API</a></li><li><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/Element/requestFullScreen" target="_blank" rel="noopener noreferrer">Element.requestFullscreen()</a></li><li><a href="https://fullscreen.spec.whatwg.org/" target="_blank" rel="noopener noreferrer">Fullscreen API</a></li><li><a href="https://www.sitepoint.com/html5-full-screen-api/" target="_blank" rel="noopener noreferrer">How to Use the HTML5 Full-Screen API</a></li><li><a href="https://github.com/rafrex/fscreen/blob/master/src/index.js" target="_blank" rel="noopener noreferrer">https://github.com/rafrex/fscreen</a></li></ul></div><div class="wx-wrapper" data-v-0de8a4bf><p class="wx-txt" data-v-0de8a4bf>欢迎关注</p><img src="http://pn4meizzc.bkt.clouddn.com/wxqr.png" class="wx-img" data-v-0de8a4bf></div><div class="beg-wrapper" data-v-1f1af99c><a href="javascript:;" class="btn show" data-v-1f1af99c><img src="http://pn4meizzc.bkt.clouddn.com/blogshang_log.png" data-v-1f1af99c></a><p class="shang-txt" data-v-1f1af99c>赏不赏，看您心情</p><img src="http://pn4meizzc.bkt.clouddn.com/blogWechatIMG35.jpeg" class="shangImg" data-v-1f1af99c></div><!----><div class="content page-nav"><p class="inner"><span class="prev">
        ← <a href="/blog/vuepress/js/useful_webapis_audiocontext.html" class="prev">
          让你的网页开口说话 —— audioContext API
        </a></span><span class="next"><a href="/blog/vuepress/js/useful_webapis_notification.html">
          几个有用的Web API——桌面通知API
        </a> →
      </span></p></div></div></div></div>
    <script src="/blog/vuepress/assets/js/26.83a2ddc3.js" defer></script><script src="/blog/vuepress/assets/js/59.5d1d0ce6.js" defer></script><script src="/blog/vuepress/assets/js/58.636557fa.js" defer></script><script src="/blog/vuepress/assets/js/57.bd168a1e.js" defer></script><script src="/blog/vuepress/assets/js/app.15770e34.js" defer></script>
  </body>
</html>
